package main

import (
	"fmt"
)

func searchMatrix(matrix [][]int, target int) bool {
	if len(matrix) == 0 {
		return false
	}
	cows, cols := len(matrix), len(matrix[0])
	cow, col := cows-1, 0
	for cow >= 0 && col < cols {
		if matrix[cow][col] == target {
			return true
		} else if matrix[cow][col] > target {
			cow -= 1
		} else {
			col += 1
		}
	}
	return false
}

func main() {
	var matrix = [][]int{{1, 4, 7, 11, 15}, {2, 5, 8, 12, 19}, {3, 6, 9, 16, 22}, {10, 13, 14, 17, 24}, {18, 21, 23, 26, 30}}
	target := 222
	a := searchMatrix(matrix, target)
	fmt.Println(a)
}
